import { Controller } from 'egg';
import * as  fs from 'fs';
import * as pump from 'mz-modules/pump';
import * as path from 'path';
// import * as sendToWormhole from 'stream-wormhole';
export default class HomeController extends Controller {
  public async upload() {
    const stream = await this.ctx.getFileStream();
    const filename = (new Date()).valueOf() + '.jpg';
    const target = path.join(this.config.baseDir, 'app/public', filename);
    const writeStream = fs.createWriteStream(target);
    await pump(stream, writeStream);
    this.ctx.body = { status: 0, message: filename }
  }
  public async uploadMP4() {
    const stream = await this.ctx.getFileStream();
    const filename = (new Date()).valueOf() + '.mp4';
    const target = path.join(this.config.baseDir, 'app/public', filename);
    const writeStream = fs.createWriteStream(target);
    await pump(stream, writeStream);
    this.ctx.body = { status: 0, message: filename }
  }
}
